package cn.ctodb.wxmp.domain;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;
import org.springframework.data.elasticsearch.annotations.Document;

import javax.persistence.*;
import java.io.Serializable;
import java.util.Objects;

import cn.ctodb.wxmp.domain.enumeration.TokenType;

/**
 * A Token.
 */
@Entity
@Table(name = "token")
@Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
@Document(indexName = "token")
public class Token implements Serializable {

    private static final long serialVersionUID = 1L;

    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;

    @Column(name = "access_token")
    private String accessToken;

    @Column(name = "expires_in")
    private Long expiresIn;

    @Column(name = "time")
    private Long time;

    @Enumerated(EnumType.STRING)
    @Column(name = "token_type")
    private TokenType tokenType;

    @ManyToOne
    private Mp mp;

    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getAccessToken() {
        return accessToken;
    }

    public Token accessToken(String accessToken) {
        this.accessToken = accessToken;
        return this;
    }

    public void setAccessToken(String accessToken) {
        this.accessToken = accessToken;
    }

    public Long getExpiresIn() {
        return expiresIn;
    }

    public Token expiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
        return this;
    }

    public void setExpiresIn(Long expiresIn) {
        this.expiresIn = expiresIn;
    }

    public Long getTime() {
        return time;
    }

    public Token time(Long time) {
        this.time = time;
        return this;
    }

    public void setTime(Long time) {
        this.time = time;
    }

    public TokenType getTokenType() {
        return tokenType;
    }

    public Token tokenType(TokenType tokenType) {
        this.tokenType = tokenType;
        return this;
    }

    public void setTokenType(TokenType tokenType) {
        this.tokenType = tokenType;
    }

    public Mp getMp() {
        return mp;
    }

    public Token mp(Mp mp) {
        this.mp = mp;
        return this;
    }

    public void setMp(Mp mp) {
        this.mp = mp;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) {
            return true;
        }
        if (o == null || getClass() != o.getClass()) {
            return false;
        }
        Token token = (Token) o;
        if (token.id == null || id == null) {
            return false;
        }
        return Objects.equals(id, token.id);
    }

    @Override
    public int hashCode() {
        return Objects.hashCode(id);
    }

    @Override
    public String toString() {
        return "Token{" +
            "id=" + id +
            ", accessToken='" + accessToken + "'" +
            ", expiresIn='" + expiresIn + "'" +
            ", time='" + time + "'" +
            ", tokenType='" + tokenType + "'" +
            '}';
    }
}
